#include "StdAfx.h"
#include "Edge.h"

namespace dhis
{

	CEdge::CEdge( )
	{
		m_vorh = true;
		m_headCol = m_headRow = m_tailCol = m_tailRow = UINT_MAX;
	}

	CEdge::CEdge(const CEdge& source)
	{
		m_vorh = source.m_vorh;
		m_headCol = source.m_headCol;
		m_headRow = source.m_headRow;
		m_tailCol = source.m_tailCol;
		m_tailRow = source.m_tailRow;
	}

	CEdge::~CEdge( )
	{

	}

	CEdge& CEdge::operator =(const CEdge& source)
	{
		if (this == &source) { return *this; }
		m_vorh = source.m_vorh;
		m_headCol = source.m_headCol;
		m_headRow = source.m_headRow;
		m_tailCol = source.m_tailCol;
		m_tailRow = source.m_tailRow;
		return *this;
	}

	bool CEdge::operator==(const CEdge &other) const
	{
		if (this == &other) { return true; }
		if (m_vorh != other.m_vorh) { return false; }
		if (m_headCol != other.m_headCol) { return false; }
		if (m_headRow != other.m_headRow) { return false; }
		if (m_tailCol != other.m_tailCol) { return false; }
		if (m_tailRow != other.m_tailRow) { return false; }
		return true;
	}

	void CEdge::Clear( )
	{
		m_vorh = true;
		m_headCol = m_headRow = m_tailCol = m_tailRow = UINT_MAX;
	}

	void CEdge::SetVorH(const bool& value)
	{
		m_vorh = value;
	}

	bool CEdge::GetVorH() const
	{
		return m_vorh;
	}

	void CEdge::SetTail(const unsigned int& row,const unsigned int& col)
	{
		m_tailRow = row;
		m_tailCol = col;
	}

	void CEdge::GetTail(unsigned int& row,unsigned int& col) const
	{
		row = m_tailRow;
		col = m_tailCol;
	}

	void CEdge::SetHead(const unsigned int& row,const unsigned int& col)
	{
		m_headRow = row;
		m_headCol = col;
	}

	void CEdge::GetHead(unsigned int& row,unsigned int& col) const
	{
		row = m_headRow;
		col = m_headCol;
	}

	bool CEdge::IsConnected(const CEdge& e) const
	{
		if ( (m_tailCol == e.m_tailCol) && (m_tailRow == e.m_tailRow) || (m_tailCol == e.m_headCol) && (m_tailRow == e.m_headRow) )
		{
			return true;
		}
		else if ( (m_headCol == e.m_tailCol) && (m_headRow == e.m_tailRow) || (m_headCol == e.m_headCol) && (m_headRow == e.m_headRow) )
		{
			return true;
		}
		else
		{
			return false;
		}
	}

	bool CEdge::GetConnectPoint(const CEdge& e, unsigned int& row, unsigned int& col) const
	{
		if ( (m_tailCol == e.m_tailCol) && (m_tailRow == e.m_tailRow) || (m_tailCol == e.m_headCol) && (m_tailRow == e.m_headRow) )
		{
			row = m_tailRow; 
			col = m_tailCol;
			return true;
		}
		else if ( (m_headCol == e.m_tailCol) && (m_headRow == e.m_tailRow) || (m_headCol == e.m_headCol) && (m_headRow == e.m_headRow) )
		{
			row = m_headRow; 
			col = m_headCol;
			return true;
		}
		else
		{
			return false;
		}
	}

}